﻿
/**
* Masque Ajax Library 0.0.3.5
* Copyright(c) 2008, 青岛领创网络科技有限公司
* @author Lookingon Team
*/

j.ajax = {
    getTransport: function() {
        return j.once(function() {
            return new XMLHttpRequest()
        }, function() {
            return new ActiveXObject('Msxml2.XMLHTTP')
        }, function() {
            return new ActiveXObject('Microsoft.XMLHTTP')
        }) ||
        false;
    },
    activeRequestCount: 0,
    randomUrl: function(_Url) {
        if (Masque.V.isString(_Url) && _Url != "") {
            if (_Url.indexOf("?") != -1) {
                _Url = _Url + "&" + Math.random();
            }
            else {
                _Url = _Url + "?" + Math.random();
            }
        }
        return _Url;
    },
    innerHTML: function(Container, URL, Tip) {
        if (typeof (Container) != "object" || typeof (URL) != "string")
            return;

        Container.innerHTML = (typeof (Tip) == "string" ? Tip : "<span style='color:red'>数据获取中请稍候......</span>");
        var xmlhttp = LAjax.getTransport();
        xmlhttp.open("Get", URL, true, null, null);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                Container.innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.send(null);
    },
    gettext: function(_URL, _callBack) {
        if (typeof (_URL) != "string")
            return "";

        var xmlhttp = LAjax.getTransport();
        xmlhttp.open("Get", _URL, true, null, null);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                if (Masque.V.isFunction(_callBack)) {
                    _callBack(xmlhttp.responseText);
                    xmlhttp = null;
                }
            }
        }
        xmlhttp.send(null);
    },
    post: function(_URL, _callBack, _params, _transfer) {
        if (typeof (_URL) != "string")
            return "";

        var xmlhttp = LAjax.getTransport();
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4) {
                _callBack(xmlhttp, _transfer);
            }
        }
        xmlhttp.open('POST', _URL, true);
        xmlhttp.setRequestHeader("content-length", _params.length);
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        //xmlhttp.setRequestHeader("Connection", "close"); //这个东西在IE6下readyState状态永远到不了4
        xmlhttp.send(_params);
    }
};


